import {filter, includes, map} from "lodash";
import {glob} from "glob";
import {parse, relative, resolve} from "path";

export const SRC_PATH = resolve(__dirname, '../');

export const getAnswerUrlByFilename = (dirName: string, Filenames: string[]):Array<{
    name: string,
    url: string,
}> => map(
    filter(
        glob.sync(resolve(SRC_PATH, `${dirName}/answer/*.ts`)),
        (url: string) => includes(Filenames ,parse(url).name),
    ),
    (url: string) => ({
        name: parse(url).name,
        url: relative(__dirname, url),
    }),
);

// const getAnswers =  async (answerUrls) => Promise.all(map(
//     answerUrls,
//     async (url) => ({
//         name: parse(url).name,
//         answer: import(url),
//     }),
// ))